package com.jzsk.variable.center.common.utils;

import java.io.File;
import java.net.URL;

/**
 * 获取系统各类路径工具类
 *
 * @author jiangli  2017/9/28
 * @version v1.0
 */
public class PathUtils {

    /**
     * 获取web项目根目录
     *
     * @return web项目根目录
     */
    public static String getWebRootPath() {
        try {
            String path = PathUtils.class.getResource("/").toURI().getPath();
            return (new File(path)).getParentFile().getParentFile().getCanonicalPath();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 获取类根目录路径
     *
     * @return 类的根目录路径
     */
    public static String getRootClassPath() {
        URL resource = PathUtils.class.getClassLoader().getResource("");
        assert resource != null;
        try {
            String path = resource.toURI().getPath();
            return (new File(path)).getAbsolutePath();
        } catch (Exception var2) {
            String path = resource.getPath();
            return (new File(path)).getAbsolutePath();
        }
    }

}
